// 2-bind使用
#include <iostream>
#include <functional>
using namespace std::placeholders;

#define CC_CALLBACK_0(__selector__, __target__, ...) std::bind(&__selector__, __target__, ##__VA_ARGS__)
#define CC_CALLBACK_1(__selector__, __target__, ...) std::bind(&__selector__, __target__, std::placeholders::_1, ##__VA_ARGS__)
#define CC_CALLBACK_2(__selector__, __target__, ...) std::bind(&__selector__, __target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)

class Test
{
private:
  /* data */
public:
  int a = 5;
  Test();
  ~Test();
  void func1(int a)
  {
    std::cout << "a: " << a << std::endl;
  }
  void func2(int a, int b)
  {
    std::cout << "a: " << a << " b: " << b << std::endl;
  }
};

Test::Test(/* args */)
{
}

Test::~Test()
{
}

// 全局函数
void func(int a, int b)
{
  std::cout << "a: " << a << " b: " << b << std::endl;
}

int main(void)
{
  // 不使用bind拷贝成员函数
  std::function<void(Test,int)> fun1 = &Test::func1;
  Test t1;
  fun1(t1,10);

  // 借助bind
  std::function<void(int)> fun2 = std::bind(&Test::func1,t1,_1);
  fun2(20);

  
  // 类的this，可以通到对象或指针来进行绑定
  printf("------------end---------------\n");
  return 0;
}